
function doSearch() {
	$('#tt').datagrid('load', {
		keyword : $('#keyword').val(),
		isUseful : $('#isUseful').combobox('getValue')
	});
	$('#tt').datagrid('unselectAll');
}

$(function() {
	$('#isUseful').combobox("select",-1);
});

function add() {
	showMyWindow('广告管理', '/ad/add', 800, 500);
}

function edit() {
	var row = $('#tt').datagrid('getSelected');
	if (row) {
		showMyWindow('广告管理', '/ad/' + row.id + '/update', 700, 500);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function abandon() {
	var row = $('#tt').datagrid('getSelected');
	var isUseful = row.isUseful;
	if(isUseful==0){
		top.showMsg(market.content.title, "数据已经是废弃状态", alert);
		return;
	}else{
		$.messager.confirm('温馨提醒', '你确定废弃本条数据吗？', function(r) {
			if (r) {
				$.get('/ad/abandon?id=' + row.id, function(data) {
					if (data.return_code == '1') {
						top.showMsg(market.content.title, data.return_msg, alert);
						doSearch();
					} else if (data.return_code == '3') {
						top.showMsg(market.content.title, data.return_msg, alert);
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				});
			}
		});
	}
}

function effect() {
	var row = $('#tt').datagrid('getSelected');
	var isUseful = row.isUseful;
	if(isUseful==1){
		top.showMsg(market.content.title, "数据已经是启用状态", alert);
		return;
	}else{
		$.messager.confirm('温馨提醒', '你确定启用本条数据吗？', function(r) {
			if (r) {
				$.get('/ad/effect?id=' + row.id, function(data) {
					if (data.return_code == '1') {
						top.showMsg(market.content.title, data.return_msg, alert);
						doSearch();
					} else if (data.return_code == '3') {
						top.showMsg(market.content.title, data.return_msg, alert);
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				});
			}
		});
	}
}


function formatterIsuseful(value) {
	if (value == 1) {
		return "启用";
	}
	if (value == 0) {
		return "作废";
	}
}

function formatterType(value) {
	if (value == 1) {
		return "组1";
	}
	if (value == 2) {
		return "组2";
	}
	if (value == 3) {
		return "组3";
	}
	if (value == 4) {
		return "组4";
	}
	if (value == 5) {
		return "组5";
	}
	if (value == 6) {
		return "组6";
	}
	if (value == 7) {
		return "组7";
	}
	if (value == 8) {
		return "组8";
	}
	if (value == 9) {
		return "组9";
	}
	if (value == 10) {
		return "组10";
	}
	if (value == 1) {
		return "组1";
	}
	if (value == 1) {
		return "组1";
	}
}
